package com.leetcode.partition11;

import java.io.*;
import java.util.*;

/**
 * @author `RKC`
 * @date 2022/2/8 16:50
 */
public class LC1001网格照明 {

    private static final int N = 20010;
    private static final int[][] dirs = {{0, 0}, {0, -1}, {0, 1}, {-1, 0}, {-1, -1}, {-1, 1}, {1, 0}, {1, -1}, {1, 1}};
    private static Map<Integer, Integer> row = new HashMap<>(N), col = new HashMap<>(N);
    //左对角线和右对角线，分别以截距式的方式存储
    private static Map<Integer, Integer> left = new HashMap<>(N), right = new HashMap<>(N);
    private static Set<Integer> set = new HashSet<>(N);

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] ss = reader.readLine().split(" ");
        int n = Integer.parseInt(ss[0]), m = Integer.parseInt(ss[1]), k = Integer.parseInt(ss[2]);
        int[][] lamps = new int[m][2], queries = new int[k][2];
        for (int i = 0; i < m; i++) {
            ss = reader.readLine().split(" ");
            lamps[i] = new int[]{Integer.parseInt(ss[0]), Integer.parseInt(ss[1])};
        }
        for (int i = 0; i < k; i++) {
            ss = reader.readLine().split(" ");
            queries[i] = new int[]{Integer.parseInt(ss[0]), Integer.parseInt(ss[1])};
        }
        writer.write(Arrays.toString(gridIllumination(n, lamps, queries)));
        writer.flush();
    }

    public static int[] gridIllumination(int n, int[][] lamps, int[][] queries) {
        for (int[] lamp : lamps) {
            int x = lamp[0], y = lamp[1];
            if (set.contains(x * n + y)) continue;
            incr(row, x);
            incr(col, y);
            incr(left, x + y);
            incr(right, x - y);
            set.add(x * n + y);
        }
        int[] ans = new int[queries.length];
        for (int i = 0; i < queries.length; i++) {
            int x = queries[i][0], y = queries[i][1];
            //查找当前位置是否被照亮
            if (row.containsKey(x) || col.containsKey(y) || left.containsKey(x + y) || right.containsKey(x - y)) ans[i] = 1;
            //如果当前位置有灯或者其余8个格子有灯，就熄灭
            for (int[] dir : dirs) {
                int nx = x + dir[0], ny = y + dir[1];
                if (nx < 0 || nx >= n || ny < 0 || ny >= n) continue;
                if (set.contains(nx * n + ny)) {
                    //灯光亮度减少1并且熄灭这个灯
                    set.remove(nx * n + ny);
                    decr(row, nx);
                    decr(col, ny);
                    decr(left, nx + ny);
                    decr(right, nx - ny);
                }
            }
        }
        return ans;
    }

    private static void incr(Map<Integer, Integer> map, int k) {
        map.put(k, map.getOrDefault(k, 0) + 1);
    }

    private static void decr(Map<Integer, Integer> map, int k) {
        Integer v = map.getOrDefault(k, null);
        if (v == null) return;
        if (v == 1) {
            map.remove(k);
            return;
        }
        map.put(k, v - 1);
    }
}
